<template>
    <div style="width:100%;height:100%">
        <div class="login-mobile-wrap">
            <div class="ms-mobile-login">
                <div class="ms-logo"></div>
                <div class="ms-title">医学影像存档与通讯系统软件</div>
                <el-form :model="param" :rules="rules" ref="login" label-width="0px" class="ms-content">
                    <el-form-item prop="username">
                        <el-input v-model="param.username" placeholder="username">
                            <el-button slot="prepend" icon="el-icon-lx-people"></el-button>
                        </el-input>
                    </el-form-item>
                    <el-form-item prop="password">
                        <el-input
                            type="password"
                            placeholder="password"
                            v-model="param.password"
                            @keyup.enter.native="submitForm()"
                        >
                            <el-button slot="prepend" icon="el-icon-lx-lock"></el-button>
                        </el-input>
                    </el-form-item>
 
                    <div class="login-btn">
                        <el-button type="primary" @click="submitForm()">登录</el-button>
                    </div>
                     <!-- <div class="login-btn">
                        <el-checkbox v-model="checked2" disabled>记住密码</el-checkbox>
                     </div> -->
                    <div class="footer-group">
                        <!-- v-if="loginType == 1" -->
                        <div class="footer-item"><el-checkbox v-model="checked" >记住密码</el-checkbox></div>
                        <!-- <div class="footer-item footer-item2" @click="$router.push({ path: '/register' })"  v-if="pageIsShow">立即注册</div> -->
                    </div>
               
                </el-form>
            </div>
        </div>
    </div>
</template>

<script>
import {Toast} from 'vant';
export default {
    name:'mobileLogin',
    data: function() {
        return {
            checked: '',
            loginType: 1,
            isMobile:this.$isMobile,
            param: {
                username: '',
                password: '',
            },
            rules: {
                username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
                password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
            },
        };
    },
    mounted(){
        let role=this.getQueryVariable('role');
        console.log('role',role)
        if(role){
            if(role === 'jqsadmin'){
                this.param.username='jqjtlinkadmin';
                this.param.password='123456';
                this.submitForm();
                return;
            }

            if(role === 'jqoadmin'){
                this.param.username='jqjtlinkuser';
                this.param.password='123456';
                this.submitForm();
                return;
            }
        }
    },
 created() {
    let username = localStorage.getItem('CLOUD_USER_NAME');
    let password = localStorage.getItem('CLOUD_USER_PASSWORD');
    if (username && password) {
      this.checked = true;
      this.param.username = username;
      this.param.password = password;
    }
    // this.lineWebSocketQrcode();
  },

    methods: {
        submitForm() {
            const loading = this.$loading({text: '登录中'});
            // http://192.168.3.148:8080/phoneLogin
            // this.$API.LOGINv2,
            this.$http.post(this.$API.LOGINv2,this.param)
            .then((res)=>{
                loading.close();
                console.log('登录信息',res)
                if(res.code == 200){
                    //   const token= sessionstorage.getItem('Token');
                    window.sessionStorage.setItem('Token', res.data.token)
                    window.sessionStorage.setItem('jqzxUserId', res.data.id)
                    window.sessionStorage.setItem('mobileUserName',res.data.name);
                    window.localStorage.setItem('userInfo',JSON.stringify(res.data));
                    if(this.isMobile){

                       if (this.loginType == 1) {
                          if (this.checked) {
                                localStorage.setItem('CLOUD_USER_NAME', this.param.username);
                                localStorage.setItem('CLOUD_USER_PASSWORD', this.param.password);
                            }else {
                                localStorage.removeItem('CLOUD_USER_NAME');
                                localStorage.removeItem('CLOUD_USER_PASSWORD');
                            }
                        }



                        Toast.success('登录成功');
                    }else{
                        this.$message.success('登录成功');
                    }
                    this.$router.push('/mobile/admin');
                }else{
                    if(this.isMobile){
                        Toast.fail(res.msg);
                    }else{
                        this.$message.error(res.msg);
                    }
                }
            })
            .catch((err)=>{
                    this.$message.error('');
                    console.log('error submit!!');
                    return false;
            })
        },
        getQueryVariable(variable) {
            var query = window.location.hash,vars=[];
            if(query && query.indexOf('?')!==-1){
                 vars = query.split("?");
            }
            for (var i = 0; i < vars.length; i++) {
                var pair = vars[i].split("=");
                if (pair[0] == variable) { return decodeURIComponent(pair[1]); }
            }
            return '';
        }
    },
};
</script>

<style scoped>
.login-mobile-wrap {
    position: relative;
    width: 100%;
    height: 100%;
    background: #409EFF;
    display: flex;
    align-items: center;
    justify-content: center;
    background: url('../../../assets/img/login-bg-moblie.png') center no-repeat;
    background-size: 100% 100%;

}
.ms-mobile-login{
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.5);
    overflow: hidden;
    padding-top:20px;
    width: 85%;
}
.login-wrap {
    position: relative;
    width: 100%;
    height: 100%;
    background: url('../../../assets/img/login-bg.png') center no-repeat;
    background-size: 100%;
}
.el-button--primary{
  background-color: #db511f;
  border-color: #db511f;
}
.ms-title {
    width: 100%;
    line-height: 50px;
    text-align: center;
    font-size: 20px;
    color: #db511f;
    border-bottom: 1px solid #ddd;
    font-weight: bold;
}
.ms-logo{
  height: 50px;
  background: url('../../../assets/img/logo.png') center no-repeat;
  background-size: auto 50px;
}
.ms-login {
    position: absolute;
    right: 20%;
    top: 50%;
    width: 350px;
    margin: -190px 0 0 -175px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.5);
    overflow: hidden;
    padding-top:20px;
}
.ms-content {
    padding: 30px 30px;
}
.login-btn {
    text-align: center;
    font-size: 0;
}
.login-btn button {
    width: 100%;
    height: 36px;
    margin-bottom: 10px;
}
.login-tips {
    font-size: 12px;
    line-height: 30px;
    color: #fff;
}
</style>